package tour.general;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

public class BaseActivity extends Activity {
	private LinearLayout mHomeToolbarLayout;
	protected final Handler mHandler = new Handler();
	protected Dialog mProgressDialog;

	protected void initToolbar() {
		LinearLayout fidatyToolbar = (LinearLayout) findViewById(R.id.home_toolbar);
		if (fidatyToolbar != null) {
			mHomeToolbarLayout = (LinearLayout) findViewById(R.id.home_layout);

			ImageButton homeButton = (ImageButton) mHomeToolbarLayout.findViewById(R.id.home_button);
			homeButton.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {
					Intent intent = new Intent(BaseActivity.this, GiroItaliaActivity.class);
					startActivity(intent);
					finish();
				}

			});
		}
	}

	protected void postToast(final String toastMsg) {
		mHandler.post(new Runnable() {

			public void run() {
				Toast.makeText(BaseActivity.this, toastMsg, Toast.LENGTH_SHORT).show();
			}
		});
	}

	protected void showProgressAsync() {

		mHandler.post(new Runnable() {

			public void run() {
				if (mProgressDialog == null) {
					mProgressDialog = new Dialog(BaseActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
					mProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					mProgressDialog.setContentView(R.layout.progress_layout);
					mProgressDialog.setCancelable(false);
					mProgressDialog.show();
				}

			}
		});
	}

	public void hideProgressAsync() {
		mHandler.post(new Runnable() {

			public void run() {
				if (mProgressDialog != null) {
					try {
						mProgressDialog.dismiss();
					} catch (Exception e) {

					} finally {
						mProgressDialog = null;
					}
				}
			}
		});

	}

}
